// my bot class for hitting the origin and through akamai

import java.io.*;
import java.util.*;
import java.net.*;

public class bot
{
    public static void main(String [] args) throws IOException
    {
        URL urlOrigin = new URL("http://origin-ts.data.foxsports.com/initbundle/2013050423/NHL/EVENT");
        URL urlAkamai = new URL("http://ts.data.edgesuite.net/livedata/bundle.html?eventNativeID=2013050423&branch=NHL&type=init");
        String headerName, headerValue;
        final BufferedReader br;
        String output = "";
        final StringBuffer outputBuffer = new StringBuffer();        
        
        headerName = "";
        headerValue = "";
        
        // open connection to akamai
        final HttpURLConnection conn = (HttpURLConnection) urlAkamai.openConnection();
        
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/json");
        conn.addRequestProperty("Pragma", "akamai-x-get-request-id, akamai-x-cache-on, akamai-x-cache-remote-on");
        
        String s = "";

        if (conn.getResponseCode() != 200)
        {
                throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }

        br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        
        while ((output = br.readLine()) != null)
        {
                outputBuffer.append(output);
        }
            
        System.out.println("-----");
        System.out.println("From Akamai: " + ((outputBuffer.toString()).trim()).substring(0,100));
        
        for (int i = 1;; i++)
        {
           headerName = conn.getHeaderFieldKey(i);
           headerValue = conn.getHeaderField(i);
        
            if (headerName == null && headerValue == null)
            {
                break;
            }          
             
            if (headerName.equals("Date"))
            {
                System.out.println(headerName + ":" + headerValue);
            }
            
            if (headerName.equals("X-Cache"))
            {
                System.out.println(headerName + ":" + headerValue);          
            }
            
            if (headerName.equals("X-Akamai-Request-ID"))
            {
                System.out.println(headerName + ":" + headerValue);
            }
          
        } // end for
        System.out.println("-----");
        
        // clean up the connection
        conn.disconnect();
    
    } // end main
    
} // end class